home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / windows / tpwin31.zip / COMMDLG.PAS < prev    next >
Pascal/Delphi Source File  |  1992-04-06  |  12KB  |  355 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Turbo Pascal for Windows Run-time Library       }
  5. {       Windows 3.1 API Interface Unit                  }
  6. {                                                       }
  7. {       Copyright (c) 1992 Borland International        }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit CommDlg;
  12.  
  13. interface
  14.  
  15. uses WinTypes;
  16.  
  17. type
  18.   POpenFilename = ^TOpenFilename;
  19.   TOpenFilename = record
  20.     lStructSize: Longint;
  21.     hWndOwner: HWnd;
  22.     hInstance: THandle;
  23.     lpstrFilter: PChar;
  24.     lpstrCustomFilter: PChar;
  25.     nMaxCustFilter: Longint;
  26.     nFilterIndex: Longint;
  27.     lpstrFile: PChar;
  28.     nMaxFile: Longint;
  29.     lpstrFileTitle: PChar;
  30.     nMaxFileTitle: Longint;
  31.     lpstrInitialDir: PChar;
  32.     lpstrTitle: PChar;
  33.     Flags: Longint;
  34.     nFileOffset: Word;
  35.     nFileExtension: Word;
  36.     lpstrDefExt: PChar;
  37.     lCustData: Longint;
  38.     lpfnHook: function (Wnd: HWnd; Msg, wParam: Word; lParam: Longint): Word;
  39.     lpTemplateName: PChar;
  40.   end;
  41.  
  42. function GetOpenFileName(var OpenFile: TOpenFilename): Bool;
  43. function GetSaveFileName(var OpenFile: TOpenFilename): Bool;
  44. function GetFileTitle(FileName, Title: PChar; TitleSize: Word): Integer;
  45.  
  46. const
  47.   ofn_ReadOnly = $00000001;
  48.   ofn_OverWritePrompt = $00000002;
  49.   ofn_HideReadOnly = $00000004;
  50.   ofn_NoChangeDir = $00000008;
  51.   ofn_ShowHelp = $00000010;
  52.   ofn_EnableHook = $00000020;
  53.   ofn_EnableTemplate = $00000040;
  54.   ofn_EnableTemplateHandle = $00000080;
  55.   ofn_NoValidate = $00000100;
  56.   ofn_AllowMultiSelect = $00000200;
  57.   ofn_ExtentionDifferent = $00000400;
  58.   ofn_PathMustExist = $00000800;
  59.   ofn_FileMustExist = $00001000;
  60.   ofn_CreatePrompt = $00002000;
  61.   ofn_ShareAware = $00004000;
  62.   ofn_NoReadOnlyReturn = $00008000;
  63.   ofn_NoTextFileCreate = $00010000;
  64.  
  65. { Return values for the registered message sent to the hook function
  66.   when a sharing violation occurs.  ofn_ShareFallThrough allows the
  67.   filename to be accepted, ofn_ShareNoWarn rejects the name but puts
  68.   up no warning (returned when the app has already put up a warning
  69.   message), and ofn_ShareWarn puts up the default warning message
  70.   for sharing violations.
  71.  
  72.   Note:  Undefined return values map to ofn_ShareWarn. }
  73.  
  74.   ofn_ShareFallThrough = 2;
  75.   ofn_ShareNoWarn = 1;
  76.   ofn_ShareWarn = 0;
  77.  
  78. type
  79.   PChooseColor = ^TChooseColor;
  80.   TChooseColor = record
  81.     lStructSize: Longint;
  82.     hWndOwner: HWnd;
  83.     hInstance: HWnd;
  84.     rgbResult: Longint;
  85.     lpCustColors: PLongint;
  86.     Flags: Longint;
  87.     lCustData: Longint;
  88.     lpfnHook: function (Wnd: HWnd; Message, wParam: Word;
  89.      lParam: Longint): Word;
  90.     lpTemplateName: PChar;
  91.   end;
  92.  
  93. function ChooseColor(var CC: TChooseColor): Bool;
  94.  
  95. const
  96.   cc_RGBInit = $00000001;
  97.   cc_FullOpen = $00000002;
  98.   cc_PreventFullOpen = $00000004;
  99.   cc_ShowHelp = $00000008;
  100.   cc_EnableHook = $00000010;
  101.   cc_EnableTemplate = $00000020;
  102.   cc_EnableTemplateHandle = $00000040;
  103.  
  104. type
  105.   PFindReplace = ^TFindReplace;
  106.   TFindReplace = record
  107.     lStructSize: Longint;        { size of this struct $20 }
  108.     hWndOwner: HWnd;              { handle to owner's window }
  109.     hInstance: THandle;           { instance handle of.EXE that
  110.                                    contains cust. dlg. template }
  111.     Flags: Longint;              { one or more of the fr_?? }
  112.     lpstrFindWhat: PChar;        { ptr. to search string    }
  113.     lpstrReplaceWith: PChar;     { ptr. to replace string   }
  114.     wFindWhatLen: Word;          { size of find buffer      }
  115.     wReplaceWithLen: Word;       { size of replace buffer   }
  116.     lCustData: Longint;          { data passed to hook fn.  }
  117.     lpfnHook: function (Wnd: HWnd; Msg, wParam: Word; lParam: Longint): Word;
  118.                                  { ptr. to hook fn. or nil }
  119.     lpTemplateName: PChar;       { custom template name     }
  120.   end;
  121.  
  122. const
  123.   fr_Down = $00000001;
  124.   fr_WholeWord = $00000002;
  125.   fr_MatchCase = $00000004;
  126.   fr_FindNext = $00000008;
  127.   fr_Replace = $00000010;
  128.   fr_ReplaceAll = $00000020;
  129.   fr_DialogTerm = $00000040;
  130.   fr_ShowHelp = $00000080;
  131.   fr_EnableHook = $00000100;
  132.   fr_EnableTemplate = $00000200;
  133.   fr_NoUpDown = $00000400;
  134.   fr_NoMatchCase = $00000800;
  135.   fr_NoWholeWord = $00001000;
  136.   fr_EnableTemplateHandle = $00002000;
  137.   fr_HideUpDown = $00004000;
  138.   fr_HideMatchCase = $00008000;
  139.   fr_HideWholeWord = $00010000;
  140.  
  141. function FindText(var FindReplace: TFindReplace): HWnd;
  142. function ReplaceText(var FindReplace: TFindReplace): HWnd;
  143.  
  144. type
  145.   PChooseFont = ^TChooseFont;
  146.   TChooseFont = record
  147.     lStructSize: Longint;       { }
  148.     hWndOwner: HWnd;             { caller's window handle   }
  149.     hDC: HDC;                    { printer DC/IC or nil    }
  150.     lpLogFont: PLogFont;        { ptr. to a LOGFONT struct }
  151.     iPointSize: Integer;                { 10 * size in points of selected font }
  152.     Flags: Longint;             { enum. type flags          }
  153.     rgbColors: Longint;         { returned text color       }
  154.     lCustData: Longint;         { data passed to hook fn.  }
  155.     lpfnHook: function (Wnd: HWnd; Msg, wParam: Word; lParam: Longint): Word;
  156.                                 { ptr. to hook function    }
  157.     lpTemplateName: PChar;      { custom template name     }
  158.     hInstance: THandle;          { instance handle of.EXE that
  159.                                   contains cust. dlg. template }
  160.     lpszStyle: PChar;           { return the style field here
  161.                                   must be lf_FaceSize or bigger }
  162.     nFontType: Word;            { same value reported to the EnumFonts
  163.                                   call back with the extra fonttype_
  164.                                   bits added }
  165.     nSizeMin: Integer;          { minimum pt size allowed & }
  166.     nSizeMax: Integer;          { max pt size allowed if
  167.                                   cf_LimitSize is used      }
  168.   end;
  169.  
  170. function ChooseFont(var ChooseFond: TChooseFont): Bool;
  171.  
  172. const
  173.   cf_ScreenFonts = $00000001;
  174.   cf_PrinterFonts = $00000002;
  175.   cf_Both = cf_ScreenFonts or cf_PrinterFonts;
  176.   cf_ShowHelp = $00000004;
  177.   cf_EnableHook = $00000008;
  178.   cf_EnableTemplate = $00000010;
  179.   cf_EnableTemplateHandle = $00000020;
  180.   cf_InitToLogfontStruct = $00000040;
  181.   cf_UseStyle = $00000080;
  182.   cf_Effects = $00000100;
  183.   cf_Apply = $00000200;
  184.   cf_AnsiOnly = $00000400;
  185.   cf_NoVectorFonts = $00000800;
  186.   cf_NoOEMFonts = cf_NoVectorFonts;
  187.   cf_NoSimulations = $00001000;
  188.   cf_LimitSize = $00002000;
  189.   cf_FixedPitchOnly = $00004000;
  190.   cf_WYSIWYG = $00008000; { must also have cf_ScreenFonts & cf_PrinterFonts }
  191.   cf_ForceFontExist = $00010000;
  192.   cf_ScalableOnly = $00020000;
  193.   cf_TTOnly = $00040000;
  194.   cf_NoFaceSel = $00080000;
  195.   cf_NoStyleSel = $00100000;
  196.   cf_NoSizeSel = $00200000;
  197.  
  198. { these are extra nFontType bits that are added to what is returned to the
  199.   EnumFonts callback routine }
  200.  
  201.   Simulated_FontType = $8000;
  202.   Printer_FontType = $4000;
  203.   Screen_FontType = $2000;
  204.   Bold_FontType = $0100;
  205.   Italic_FontType = $0200;
  206.   Regular_FontType = $0400;
  207.  
  208.   wm_ChooseFont_GetLogfont = wm_User + 1;
  209.  
  210.  
  211. { strings used to obtain unique window message for communication
  212.   between dialog and caller }
  213.  
  214.   LBSelChString = 'commdlg_LBSelChangedNotify';
  215.   ShareViString = 'commdlg_ShareViolation';
  216.   FileOKString = 'commdlg_FileNameOK';
  217.   ColorOKString = 'commdlg_ColorOK';
  218.   SetRGBString = 'commdlg_SetRGBColor';
  219.   FindMsgString = 'commdlg_FindReplace';
  220.   HelpMsgString = 'commdlg_help';
  221.  
  222. { HIWORD values for lParam of commdlg_LBSelChangeNotify message }
  223.  
  224. const
  225.   cd_LBSelNoItems = -1;
  226.   cd_LBSelChange  = 0;
  227.   cd_LBSELSUB     = 1;
  228.   cd_LBSelAdd     = 2;
  229.  
  230. type
  231.   PPrintDlg = ^TPrintDlg;
  232.   TPrintDlg = record
  233.     lStructSize: Longint;
  234.     hWndOwner: HWnd;
  235.     hDevMode: THandle;
  236.     hDevNames: THandle;
  237.     hDC: HDC;
  238.     Flags: Longint;
  239.     nFromPage: Word;
  240.     nToPage: Word;
  241.     nMinPage: Word;
  242.     nMaxPage: Word;
  243.     nCopies: Word;
  244.     hInstance: THandle;
  245.     lCustData: Longint;
  246.     lpfnPrintHook: function (Wnd: HWnd; Msg, wParam: Word;
  247.       lParam: Longint): Integer;
  248.     lpfnSetupHook: function (Wnd: HWnd; Msg, wParam: Word;
  249.       lParam: Longint): Integer;
  250.     lpPrintTemplateName: PChar;
  251.     lpSetupTemplateName: PChar;
  252.     hPrintTemplate: THandle;
  253.     hSetupTemplate: THandle;
  254.   end;
  255.  
  256. function PrintDlg(var PrintDlg: TPrintDlg): Bool;
  257.  
  258. const
  259.   pd_AllPages = $00000000;
  260.   pd_Selection = $00000001;
  261.   pd_PageNums = $00000002;
  262.   pd_NoSelection = $00000004;
  263.   pd_NoPageNums = $00000008;
  264.   pd_Collate = $00000010;
  265.   pd_PrintToFile = $00000020;
  266.   pd_PrintSetup = $00000040;
  267.   pd_NoWarning = $00000080;
  268.   pd_ReturnDC = $00000100;
  269.   pd_ReturnIC = $00000200;
  270.   pd_ReturnDefault = $00000400;
  271.   pd_ShowHelp = $00000800;
  272.   pd_EnablePrintHook = $00001000;
  273.   pd_EnableSetupHook = $00002000;
  274.   pd_EnablePrintTemplate = $00004000;
  275.   pd_EnableSetupTemplate = $00008000;
  276.   pd_EnablePrintTemplateTHandle = $00010000;
  277.   pd_EnableSetupTemplateTHandle = $00020000;
  278.   pd_UseDevModeCopies = $00040000;
  279.   pd_DisablePrintToFile = $00080000;
  280.   pd_HidePrintToFile = $00100000;
  281.  
  282. type
  283.   PDevNames = ^TDevNames;
  284.   TDevNames = record
  285.     wDriverOffset: Word;
  286.     wDeviceOffset: Word;
  287.     wOutputOffset: Word;
  288.     wDefault: Word;
  289.   end;
  290.  
  291. const
  292.   dn_DefaultPrn = $0001;
  293.  
  294. function CommDlgExtendedError: Longint;
  295.  
  296. const
  297.   cderr_DialogFailure    = $FFFF;
  298.  
  299.   cderr_GeneralCodes     = $0000;
  300.   cderr_StructSize       = $0001;
  301.   cderr_Initialization   = $0002;
  302.   cderr_NoTemplate       = $0003;
  303.   cderr_NoHInstance      = $0004;
  304.   cderr_LoadStrFailure   = $0005;
  305.   cderr_FindResFailure   = $0006;
  306.   cderr_LoadResFailure   = $0007;
  307.   cderr_LockResFailure   = $0008;
  308.   cderr_MemAllocFailure  = $0009;
  309.   cderr_MemLockFailure   = $000A;
  310.   cderr_NoHook           = $000B;
  311.   cderr_RegisterMsgFail  = $000C;
  312.  
  313.   pderr_PrinterCodes     = $1000;
  314.   pderr_SetupFailure     = $1001;
  315.   pderr_ParseFailure     = $1002;
  316.   pderr_RetDefFailure    = $1003;
  317.   pderr_LoadDrvFailure   = $1004;
  318.   pderr_GetDevModeFail   = $1005;
  319.   pderr_InitFailure      = $1006;
  320.   pderr_NoDevices        = $1007;
  321.   pderr_NoDefaultPrn     = $1008;
  322.   pderr_DNDMMismatch     = $1009;
  323.   pderr_CreateICFailure  = $100A;
  324.   pderr_PrinterNotFound  = $100B;
  325.   pderr_DefaultDifferent = $100C;
  326.  
  327.   cferr_ChooseFontCodes  = $2000;
  328.   cferr_NoFonts          = $2001;
  329.   cferr_MaxLessThanMin   = $2002;
  330.  
  331.   fnErr_FilenameCodes    = $3000;
  332.   fnErr_SubclassFailure  = $3001;
  333.   fnErr_InvalidFilename  = $3002;
  334.   fnErr_BufferTooSmall   = $3003;
  335.  
  336.   frErr_FindReplaceCodes = $4000;
  337.   frErr_BufferLengthZero = $4001;
  338.  
  339.   ccErr_ChooseColorCodes = $5000;
  340.  
  341. implementation
  342.  
  343. function GetOpenFileName;                  external 'COMMDLG'  index 1;
  344. function GetSaveFileName;                  external 'COMMDLG'  index 2;
  345. function GetFileTitle;                     external 'COMMDLG'  index 27;
  346. function ChooseColor;                      external 'COMMDLG'  index 5;
  347. function FindText;                         external 'COMMDLG'  index 11;
  348. function ReplaceText;                      external 'COMMDLG'  index 12;
  349. function ChooseFont;                       external 'COMMDLG'  index 15;
  350. function PrintDlg;                         external 'COMMDLG'  index 20;
  351. function CommDlgExtendedError;             external 'COMMDLG'  index 26;
  352.  
  353. end.
  354.  
  355.